<?
include "WikiParser.php";

$examples = array( 
		"Full CoolSolutions Article",
		"Sections",
		"Texts",
		"Definition Lists",
		"Indenting text",
		"Code",
		"Images",
		"Lists",
		"Blockquotes and callouts",
		"Links",
		"Tables"
	);

function getParameter( $aParam )
{
	$aParam = isset( $_POST[$aParam] ) ? $_POST[$aParam] : "";
	return $aParam;
}

$attributes = array( 
	"sample" => "" );

foreach( $attributes as $key=>$value )
{
	$attributes[$key] = getParameter( $key );
}
?>
<head>
<script>
var example = new Array();

example[ 0 ] = "= Wiki to CoolSolutions Converter =\n\
== A bit of Php, a taste of regular expressions... That's it! ==\n\
\n\
Have an idea to share on CoolSolutions? Don't want to use to much time writing it with HTML tags? Use the Wiki format! I adapted a Wiki parser written in Php from [http://code.blitzaffe.com http://code.blitzaffe.com]. I added some styles that were not included such as blockquotes, callouts, tables with headers and table of contents.\n\
\n\
This document shows the different Wiki constructions you can use to write your CoolSolutions. I wrote this article using all the Wiki components available.\n\
\n\
=== Content of the attached archive ===\n\
Here is the content of the file Wiki2Cool.zip:\n\
\n\
 ./Wiki2Cool\n\
   +- WikiParser.php\n\
   +- convert.php\n\
   +- index.php\n\
   +- main.css\n\
   +- tier4.css\n\
   +- Wiki2Cool_OnlineConverter_1.png\n\
   +- Wiki2Cool_OnlineConverter_2.png\n\
   +- Wiki2Cool_OnlineConverter_3.png\n\
   +- Wiki2Cool_Sections.png\n\
   +- sample.txt\n\
   +- sample.html\n\
\n\
Details:\n\
\n\
* \$WikiParser.php$: class used to parse Wiki text. This class has been updated to handle Novell classes such as \"callout\" on div tags, \"spread\" class for lists, \"code\" class for preformatted text and inline code and also new tables components.\n\
* \$convert.php$: script to convert Wiki text file on the command line. To use it, execute $\"convert.php sample.txt > sample.html\"$.\n\
* \$index.php$: if you copy all the files to a Apache/Php folder, this page will offer you an online page to convert and preview Wiki content to HTML. You can also try [http://wiki2cool.kalfane.org http://wiki2cool.kalfane.org] if it is available. It is an install of my files on an accessible public web server. Use it to test your Wiki content!\n\
* $*.css$: files to have a Novell style for index.php. It is not fully like the CoolSolutions website but it is close to it.\n\
* $*.png$: images included in this article to illustrate sections, table of contents and the online converter\n\
* \$sample.txt$: the source code of this article in Wiki format!\n\
* \$sample.html$: the final HTML code of this article\n";

example[ 1 ] = "=== Sections ===\n\
To create a section, just surround your line with one or more equal signs according to the level. You can generate a Table of Contents automatically if you put {{__TOC__}} at '''the end''' of the document. Then, when you generate the HTML, you can move it to the beginning of the document.\n\
\n\
If you use the following:\n\
\n\
 = This is the Title =\n\
 == This is the Sub-Title ==\n\
 === Introduction ===\n\
 Lorem ipsum lorem ipsum ipsum lorem ipsum\n\
 === Part 1 ===\n\
 ==== Sub-Part 1 ====\n\
 Lorem ipsum lorem ipsum ipsum lorem ipsum\n\
 ==== Sub-Part 2 ====\n\
 Lorem ipsum lorem ipsum ipsum lorem ipsum\n\
 === Part 2 ===\n\
 Lorem ipsum lorem ipsum ipsum lorem ipsum\n\
 === Summary ===\n\
 Lorem ipsum lorem ipsum ipsum lorem ipsum\n\
 {{__TOC__}}\n\
\n\
The result will magically be:\n\
\n\
[[Image:Wiki2Cool_Sections.png|center|Screenshot of the result]]\n";

example[ 2 ] = "=== Displaying Texts ===\n\
If you type text on several lines, they will be joined by default unless there is two line returns, which means a new paragraph, or if you force the line return using the code <nowiki>\"///\"</nowiki>. \n\
\n\
For instance if you type the following:\n\
\n\
 This is regular text. \n\
 The second line is in the same paragraph.\n\
 \n\
 It is also possible to force///line breaks\n\
\n\
The result will be the following:\n\
\n\
This is regular text. \n\
The second line is in the same paragraph.\n\
\n\
It is also possible to force///line breaks\n\
\n\
You can also format code inline by surrounding it with dollars \"$\":\n\
\n\
 \$convert.php$: script to convert Wiki text to HTML\n\
\n\
The result will be the following:\n\
\n\
\$convert.php$: script to convert Wiki text to HTML\n\
\n\
To display a separator, use 4 dashes \"----\":\n\
\n\
 Text above separator\n\
 ----\n\
 Text under separator\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
Text above separator\n\
----\n\
Text under separator\n\
\n\
There several level of emphasis you can use by surrounding the text with multiple quotes:\n\
\n\
 * ''level 2 emphasis''\n\
 * '''level 3 emphasis'''\n\
 * ''''level 4 emphasis''''\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
* ''level 2 emphasis''\n\
* '''level 3 emphasis'''\n\
* ''''level 4 emphasis''''\n";

example[ 3 ] = "=== Displaying Definition Lists ===\n\
Use \";\" and \":\" separator to display terms and definitions:\n\
\n\
 ; '''yes''' : opposite of no\n\
 ; '''no''' : opposite of yes\n\
 ; '''maybe'''\n\
 : somewhere in between yes and no\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
; '''yes''' : opposite of no\n\
; '''no''' : opposite of yes\n\
; '''maybe'''\n\
: somewhere in between yes and no\n";

example[ 4 ] = "=== Indenting text ===\n\
Use \":\" to indent text:\n\
\n\
 Normal\n\
 : indented\n\
 : more indentation\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
Normal\n\
: indented\n\
: more indentation\n";

example[ 5 ] = "=== Displaying Code ===\n\
To display preformatted code add a space at the beginning of the lines:\n\
\n\
 <\?xml version=\"1.0\"\?>\n\
 <nodes>\n\
   <node id=\"node1\"/>\n\
   <node id=\"node2\"/>\n\
   <node id=\"node3\"/>\n\
   <node id=\"node4\"/>\n\
 </nodes>\n\
\n\
Another one:\n\
\n\
 34 '''print''' \"Listing filtered files v2 (list comprehension)\"\n\
 35 dir = \".\"\n\
 36 ext = \"py\"\n\
 37 files = [f <b>for</b> f <b>in</b> os.listdir( dir ) '''if''' re.search('^.*.' + ext + '$',f) ]\n\
 38 '''print''' \"n\".join( files )\n\
 39 '''print''' \"Found %d .%s file(s) in current directory\" % ( len( files ), ext )\n\
 40 '''print''' \"\"\n";

example[ 6 ] = "=== Displaying Images ===\n\
\n\
You can display images using the following format: [[Image:url|align|text]]. The image can be aligned on the left with text on the right, aligned on the right with text on the left or centered with text under it.\n\
\n\
For instance:\n\
\n\
 [[Image:http://www.novell.com/communities/sites/all/themes/novell/images/icons/feature.gif|right|CoolSolution Icon]]\n\
 Conectitur contumeliae, interesse meminerimus poenis sapiens. Aenean aeque dominationis eodem invenire malesuada paulo. Aegritudinem careret didicisse disciplinae discordant, emancipaverat ferant infimum laboramus nos oblivione officiis rudem sadipscing solum. Arte atque dicitur efficere fingitur gratissimo partem quamvis unum. Angatur asperiores compositis discordant, excelsus ipse magnis nemore, no reperiuntur suum vicinum videri. \n\
 \n\
 [[Image:http://www.novell.com/communities/sites/all/themes/novell/images/icons/feature.gif|left|CoolSolution Icon]]\n\
 Conectitur contumeliae, interesse meminerimus poenis sapiens. Aenean aeque dominationis eodem invenire malesuada paulo. Aegritudinem careret didicisse disciplinae discordant, emancipaverat ferant infimum laboramus nos oblivione officiis rudem sadipscing solum. Arte atque dicitur efficere fingitur gratissimo partem quamvis unum. Angatur asperiores compositis discordant, excelsus ipse magnis nemore, no reperiuntur suum vicinum videri. \n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
[[Image:http://www.novell.com/communities/sites/all/themes/novell/images/icons/feature.gif|right|CoolSolution Icon]]\n\
Conectitur contumeliae, interesse meminerimus poenis sapiens. Aenean aeque dominationis eodem invenire malesuada paulo. Aegritudinem careret didicisse disciplinae discordant, emancipaverat ferant infimum laboramus nos oblivione officiis rudem sadipscing solum. Arte atque dicitur efficere fingitur gratissimo partem quamvis unum. Angatur asperiores compositis discordant, excelsus ipse magnis nemore, no reperiuntur suum vicinum videri. \n\
\n\
[[Image:http://www.novell.com/communities/sites/all/themes/novell/images/icons/feature.gif|left|CoolSolution Icon]]\n\
Conectitur contumeliae, interesse meminerimus poenis sapiens. Aenean aeque dominationis eodem invenire malesuada paulo. Aegritudinem careret didicisse disciplinae discordant, emancipaverat ferant infimum laboramus nos oblivione officiis rudem sadipscing solum. Arte atque dicitur efficere fingitur gratissimo partem quamvis unum. Angatur asperiores compositis discordant, excelsus ipse magnis nemore, no reperiuntur suum vicinum videri. \n\
\n\
If you have a look at the WikiParser.php file, you can extend the features by adding your own Wiki components. For instance I added a spacial one:\n\
\n\
 {*cool_solutions}\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
{*cool_solutions}\n";

example[ 7 ] = "=== Displaying Lists ===\n\
==== Unordered list ====\n\
Use stars \"*\" followed by space to build your normal or multi-level unordered lists:\n\
\n\
 * list\n\
 * list\n\
 ** list\n\
 ** list\n\
 * list\n\
 * list\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
* list\n\
* list\n\
** list\n\
** list\n\
* list\n\
* list\n\
==== Unordered list, spread class ====\n\
Use \"o\" followed by space to build your normal or multi-level unordered lists with spread class:\n\
\n\
 o list\n\
 o list\n\
 oo list\n\
 oo list\n\
 o list\n\
 o list\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
o list\n\
o list\n\
oo list\n\
oo list\n\
o list\n\
o list\n\
==== Ordered list ====\n\
Use sharps \"#\" followed by space to build your normal or multi-level ordered lists:\n\
\n\
 # list\n\
 # list\n\
 ## list\n\
 ## list\n\
 ## list\n\
 # list\n\
 ## list\n\
 ## list\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
# list\n\
# list\n\
## list\n\
## list\n\
## list\n\
# list\n\
## list\n\
## list\n\
==== Mixed list ====\n\
You can mix ordered and unordered lists:\n\
\n\
 * One bullet\n\
 * Another '''bullet'''\n\
 *# a list item\n\
 *# another list item\n\
 *#* unordered, ordered, unordered\n\
 *#* again\n\
 *# back down one\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
* One bullet\n\
* Another '''bullet'''\n\
*# a list item\n\
*# another list item\n\
*#* unordered, ordered, unordered\n\
*#* again\n\
*# back down one\n";

example[ 8 ] = "=== Displaying blockquotes and callouts ===\n\
To display callouts use \"@\" character at the beginning of the lines:\n\
\n\
 @'''Note:'''\n\
 @This is a callout.\n\
 @Use \"@\" at the beginning of each line.\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
@'''Note:'''\n\
@This is a callout.\n\
@Use \"@\" at the beginning of each line.\n\
\n\
To display blockquote use percent \"%\" character at the beginning of the lines:\n\
\n\
 %'''Note:'''\n\
 %This is a blockquote.\n\
 %Use \"%\" at the beginning of each line.\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
%'''Note:'''\n\
%This is a blockquote.\n\
%Use \"%\" at the beginning of each line.\n";

example[ 9 ] = "=== Displaying Links ===\n\
You can display external links in 3 different manners:\n\
* Note Link\n\
* Normal Link\n\
* Labeled Link\n\
\n\
For instance:\n\
\n\
 Note Link: Go to Novell[http://www.novell.com] or Novell Support[http://support.novell.com]!\n\
 \n\
 Normal Link: [http://www.novell.com http://www.novell.com]\n\
 \n\
 Labeled Link: [http://www.novell.com Novell Website]\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
Note Link: Go to Novell[http://www.novell.com] or Novell Support[http://support.novell.com]!\n\
\n\
Normal Link: [http://www.novell.com http://www.novell.com]\n\
\n\
Labeled Link: [http://www.novell.com Novell Website]\n";

example[ 10 ] = "=== Displaying Tables ===\n\
==== Without header ====\n\
Using the \"!\" separator, you can easily display basic table without header:\n\
\n\
 !aaa!bbb!ccc!ddd!eee\n\
 !aaa!bbb!ccc!ddd!eee\n\
 !aaa!bbb!ccc!ddd!eee\n\
 !aaa!bbb!ccc!ddd!eee\n\
 !aaa!bbb!ccc!ddd!eee\n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
!aaa!bbb!ccc!ddd!eee\n\
!aaa!bbb!ccc!ddd!eee\n\
!aaa!bbb!ccc!ddd!eee\n\
!aaa!bbb!ccc!ddd!eee\n\
!aaa!bbb!ccc!ddd!eee\n\
\n\
==== With horizontal header ====\n\
Use pipe \"|\" separator on the first line to display horizontal header:\n\
\n\
 | aaa | bbb | ccc | ddd | eee \n\
 ! aaa ! bbb ! ccc ! ddd ! eee \n\
 ! aaa ! bbb ! ccc ! ddd ! eee \n\
 ! aaa ! bbb ! ccc ! ddd ! eee \n\
 ! aaa ! bbb ! ccc ! ddd ! eee \n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
| aaa | bbb | ccc | ddd | eee \n\
! aaa ! bbb ! ccc ! ddd ! eee \n\
! aaa ! bbb ! ccc ! ddd ! eee \n\
! aaa ! bbb ! ccc ! ddd ! eee \n\
! aaa ! bbb ! ccc ! ddd ! eee \n\
\n\
==== With vertical header ====\n\
Use underscore \"_\" separator at the beginning of each line to display vertical header:\n\
\n\
 _ aaa ! aaa ! aaa ! aaa ! aaa \n\
 _ bbb ! bbb ! bbb ! bbb ! bbb \n\
 _ ccc ! ccc ! ccc ! ccc ! ccc \n\
 _ ddd ! ddd ! ddd ! ddd ! ddd \n\
 _ eee ! eee ! eee ! eee ! eee \n\
\n\
Here is the result of the conversion from Wiki to HTML:\n\
\n\
_ aaa ! aaa ! aaa ! aaa ! aaa \n\
_ bbb ! bbb ! bbb ! bbb ! bbb \n\
_ ccc ! ccc ! ccc ! ccc ! ccc \n\
_ ddd ! ddd ! ddd ! ddd ! ddd \n\
_ eee ! eee ! eee ! eee ! eee \n";

example[ 11 ] = "=== Conclusion ===\n\
I hope that you will be able to write your CoolSolutions article faster thanks to the Wiki format. \n\
\n\
You can convert your files on the command line using the following command:\n\
\n\
 Wiki2Cool> ./convert.php sample.txt > sample.html\n\
\n\
Don't hesitate to use the online converter available at [http://wiki2cool.kalfane.org http://wiki2cool.kalfane.org] or install one on your server by just copying the content of the archive in an Apache/Php folder. Here are some screenshots:\n\
\n\
[[Image:Wiki2Cool_OnlineConverter_1.png|center|Online converter 1]]\n\
\n\
Result of the submission:\n\
\n\
[[Image:Wiki2Cool_OnlineConverter_2.png|center|Online converter 2]]\n\
[[Image:Wiki2Cool_OnlineConverter_3.png|center|Online converter 3]]\n\
\n\
Also don't hesitate to have a look at the Wiki source of this article that you will find in the file sample.txt. \n\
If you add new Wiki components in the WikiParser class, keep me posted! \n\
Happy writing!\n\
\n\
{{__TOC__}}";

function loadSample()
{
	var sample = document.form1.sample.options[ document.form1.sample.selectedIndex ].value;

	if ( sample == "" ) return;

	var result = ""
	if ( sample == "0" )
	{
		for( i = 0 ; i < example.length ; i++ )
		{
			result = result + example[ i ];
		}
	}
	else
	{
		result = example[ sample ];
	}
	document.form1.wiki.value = result;
	document.form1.submit();
}
</script>
<style type="text/css" media="all">@import "style.css";</style>
<style type="text/css">
@import url(tier4.css);
h1 { font-size: 11pt; }
h2 { font-size: 10pt; }
h3 { font-size: 9pt; }
pre.code { font-size: 5pt; width: 450px; }
table  { width: 100%; }
table.main  { width: 500px; }
tr.odd { background-color: #eeeeee; }
tr.even { background-color: #ffffff; }
* { font-size: 7pt; }
ul.spread { line-height: 2em; }
.callout { background-color: #eeeeee; padding: 5px; border-style: solid; border-color: #cccccc; border-width: 1px 0px 1px 0px; }
blockquote {padding: 5px; border-style: solid; border-color: #66cc66; border-width: 0px 0px 0px 15px; float: left; }
</style>
</head>
<body>
<table align="center" class="main">
<tr><td>

<h1>wiki2cool - Wiki to CoolSolutions converter</h1>
<h3>Wiki text</h3>
<p>Please enter your article in Wiki format:</p>
<form action="index.php" method="POST" name="form1">
	<select name="sample">
		<option value="">- Choose a sample -</option>
<?
foreach( $examples as $k=>$v )
{
	echo "<option value=\"{$k}\"";
	if ( "XXX".$attributes["sample"] == "XXX".$k ) echo " selected=\"selected\"";
	echo ">{$v}</option>";
}
?>
	</select><input type="button" value="Load and Convert Sample" onclick="loadSample();"/><br/>
	<textarea cols="70" rows="12" name="wiki"><? if ( isset( $_POST["wiki"] ) ) echo htmlentities( stripslashes($_POST["wiki"]) ); ?></textarea><br/>
	<input type="submit" value="Convert Content"/>
	<input type="button" value="Clear Text" onclick="document.form1.wiki.value = '';"/>
	<input type="reset" value="Reset"/>
</form>

<h3>CoolSolutions HTML source</h3>
<p>Here is the source result of the conversion from Wiki to HTML:</p>
<textarea readonly="readonly" cols="70" rows="12" name="html"><? if ( isset( $_POST["wiki"] ) ) { $wikiparser = new WikiParser(); $wikitext = stripslashes($_POST["wiki"]); $htmlresult = $wikiparser->parse($wikitext); echo  htmlentities($htmlresult); } ?></textarea>

<h3>CoolSolutions HTML preview</h3>
<p>Here is the preview result of the conversion from Wiki to HTML:</p>
<table width="100%">
<tr><td style="border-style: solid; border-color: #999999; border-width: 1px; padding: 10px;">

<? if ( isset( $_POST["wiki"] ) ) echo $htmlresult; ?>

</td></tr>
</table>

</td></tr>
</table>
</body>
